package com.example.demo.controller;

import com.example.comon.domain.R;
import com.example.demo.domain.Bo.AddDepartmentBo;
import com.example.demo.domain.Bo.DepartmentBo;
import com.example.demo.domain.Department;
import com.example.demo.domain.Vo.DepartmentVo;
import com.example.demo.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
@Api(value = "department" , tags = "部门控制器")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @GetMapping("/getDepartment")
    @ApiOperation("获取部门列表")
    public R<List<DepartmentVo>> getDepartment(DepartmentBo bo){
        Department department = new Department();
        department.setDepartmentName(bo.getDepartmentName());
        List<DepartmentVo>list = departmentService.selectDepartment(department);
        return R.success(list);
    }

    @PostMapping("/AddDepartment")
    @ApiOperation("新增部门")
    public R<Department> addDepartment(@RequestBody AddDepartmentBo bo){
        Department department = new Department();
        department.setDepartmentName(bo.getDepartmentName());
        department.setSuperiorDepartmentId(bo.getSuperiorDepartmentId());
        department.setLeader(bo.getLeader());
        department.setDisplaySequence(bo.getDisplaySequence());
        department.setNumber(bo.getNumber());
        departmentService.insertDepartment(department);
        return R.success(department);
    }

    @PostMapping("/updateDepartmentById")
    @ApiOperation("修改部门")
    public R updateDepartmentById(@RequestBody Department department){
        departmentService.updateDepartmentById(department);
        return R.success();
    }

    @DeleteMapping("/delDepartmentById")
    @ApiOperation("删除部门")
    public R delDepartmentById(long departmentId){
        departmentService.delDepartmentById(departmentId);
        return R.success();
    }
}
